#pragma once
#include <memory>
#include <list>

#include "View.h"
#include "Size.h"
#include "Point.h"
#include "SkCanvas.h"

class TreeView;

class TreeItem
{
public:
	TreeItem();
	virtual ~TreeItem();

	void paint(SkCanvas* canvas);
	virtual void paintItem(SkCanvas* canvas);
	virtual void paintChildren(SkCanvas* canvas);

	int getHeightWithChildren();

	bool hasChildren();

	virtual bool updateLayout();

	TreeItem* getItemByPos(gfx::Point pos);

private:
	friend class TreeView;
	bool is_expansion_;
	std::wstring str_;
	gfx::Size size_;
	std::shared_ptr<TreeItem> parent_;
	std::list<std::shared_ptr<TreeItem>> chadren_;


	SkFont font_;
};

class TreeView :
	public View
{
public:
	TreeView(View* parent);
	virtual ~TreeView();

	std::shared_ptr<TreeItem> AddString(std::wstring str, std::shared_ptr<TreeItem> item = std::shared_ptr<TreeItem>());
	
protected:
	virtual bool paint(SkCanvas* canvas);

	virtual bool paintBackground(SkCanvas* canvas);

	virtual bool paintFrontground(SkCanvas* canvas);

	virtual bool processMouseEvent(MouseEvent& event);


	virtual bool updateLayout();
private:
	int getScrollHight();

	void goToPos(int pos);

	void PointToPos(gfx::Point point, gfx::Point& pos);

	TreeItem* getItemByPos(gfx::Point pos);

	void fixShowPos();

private:
	std::list<std::shared_ptr<TreeItem>> items_;

	int show_pos_;
};

